Textcsv::App.controllers :file do

  # get :index, :map => '/foo/bar' do
  #   session[:foo] = 'bar'
  #   render 'index'
  # end

  # get :sample, :map => '/sample/url', :provides => [:any, :js] do
  #   case content_type
  #     when :js then ...
  #     else ...
  # end

  # get :foo, :with => :id do
  #   "Maps to url '/foo/#{params[:id]}'"
  # end

  # get '/example' do
  #   'Hello world!'
  # end

  get :index do

    render 'file/hiddeniframe', :layout => false
  end

  post :file_import do
    require 'roo'
    xlsx = Roo::Spreadsheet.open(params[:file_to_upload][:tempfile], extension: :xlsx)
    user_list = xlsx.sheet(0)
    @length = user_list.column(1).length
    FileInstance.set_length(@length)
    for i in 2..@length
      FileInstance.set_currentlength(i)
      if DidiCustPhone.where(number: user_list.row(i)[1], cust_group_id: params[:user_group]).exists?
        next
      end
      @didi_cust_phone = DidiCustPhone.new
      @didi_cust_phone.name = user_list.row(i)[0]
      @didi_cust_phone.number = user_list.row(i)[1]
      @didi_cust_phone.other = "保险过期时间:"+user_list.row(i)[2].to_s
      @didi_cust_phone.cust_group = CustGroup.find(params[:user_group])
      @didi_cust_phone.save
      puts @info.to_json
    end



  end

  get :fileprogress do
    len = FileInstance.get_length
    if len != 0
      current = FileInstance.get_currentlength
      @present = current*100/len
      return @present.to_s
    end
    0.to_s


  end

end
